package com.izhangqian.pluginapk;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;

public class BasePluginActivity extends Activity implements IActivity {

    public Activity mProxyActivity;

    @Override
    public void attach(Activity proxyActivity) {
        mProxyActivity = proxyActivity;
    }

    @Override
    public void onCreate(Bundle saveInstanceState) {
        if (mProxyActivity == null) {
            super.onCreate(saveInstanceState);
        }
    }

    @Override
    protected void attachBaseContext(Context newBase) {
        if (mProxyActivity != null) {
            super.attachBaseContext(mProxyActivity);
            return;
        }
        super.attachBaseContext(newBase);
    }

    @Override
    public void setContentView(int layoutResID) {
        if(mProxyActivity != null) {
            mProxyActivity.setContentView(layoutResID);
        }else{
            super.setContentView(layoutResID);
        }
    }

    @Override
    public Intent getIntent() {
        if (mProxyActivity != null) {
            return mProxyActivity.getIntent();
        }
        return super.getIntent();
    }

    @Override
    public Resources getResources() {
        if (mProxyActivity != null) {
            return mProxyActivity.getResources();
        }
        return super.getResources();
    }

    @Override
    public <T extends View> T findViewById(int id) {
        if (mProxyActivity != null) {
            return mProxyActivity.findViewById(id);
        }
        return super.findViewById(id);
    }


}
